//
//  PersonalView.m
//  DLT-daluntai
//
//  Created by Apple on 17/3/22.
//  Copyright © 2017年 BW. All rights reserved.
//

#import "PersonalView.h"

@implementation PersonalView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self fangfa];
    }
    return self;
}
- (void)fangfa{
    
    [self addSubview:self.theTable];
    [self addSubview:self.headView];
    [self.headView addSubview:self.imgButton];
    [self.headView addSubview:self.loginButton];
    [self.headView addSubview:self.setButton];
    [self.headView addSubview:self.shoppingButton];
    self.theTable.tableHeaderView=self.headView;
    
}
//// 个人中心表格
//@property (nonatomic,strong) UITableView *theTable;
//// 表格头视图
//@property (nonatomic,strong) UIView *headView;
//// 头像按钮
//@property (nonatomic,strong) UIButton *imgButton;
//// 登录按钮
//@property (nonatomic,strong) UIButton *loginButton;
//// 设置按钮
//@property (nonatomic,strong) UIButton *setButton;
//// 购物车按钮
//@property (nonatomic,strong) UIButton *shoppingButton;
//// 待付款
//@property (nonatomic,strong) UIButton *paymentButton;
//// 待发货
//@property (nonatomic,strong) UIButton *deliveryButton;
//// 待收货
//@property (nonatomic,strong) UIButton *receivedButton;
//// 待评价
//@property (nonatomic,strong) UIButton *evaluationButton;

// 表格
-(UITableView *)theTable{
    if (!_theTable) {
        _theTable=[[UITableView alloc]initWithFrame:CGRectMake(0, -20, self.frame.size.width, self.frame.size.height) style:UITableViewStyleGrouped];
    }
    _theTable.delegate=self;
    _theTable.dataSource=self;
    return _theTable;
}
// 表格头视图
-(UIView *)headView{
    if (!_headView) {
        _headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 260)];
    }
    _headView.backgroundColor=[UIColor colorWithRed:(253/255.0) green:(113/255.0) blue:(46/255.0) alpha:1];
    
    return _headView;
}
// 头像按钮
-(UIButton *)imgButton{
    if (!_imgButton) {
        _imgButton=[[UIButton alloc]initWithFrame:CGRectMake(self.frame.size.width/2-60, 70, 110, 110)];
    }
    _imgButton.layer.cornerRadius=55;
    _imgButton.layer.masksToBounds=YES;
    [_imgButton setImage:[UIImage imageNamed:@"设施_小猫.png"] forState:0];
    _imgButton.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [_imgButton addTarget:self action:@selector(denglu) forControlEvents:UIControlEventTouchUpInside];
    
    return _imgButton;
}
-(void)denglu{
    
}
// 登录按钮
-(UIButton *)loginButton{
    if (!_loginButton) {
        _loginButton=[[UIButton alloc]initWithFrame:CGRectMake(self.frame.size.width/2-80, 200, 150, 30)];
    }
    [_loginButton addTarget:self action:@selector(denglu) forControlEvents:UIControlEventTouchUpInside];
    [_loginButton setTitle:@" 登录  /  注册 " forState:0];
    [_loginButton.titleLabel setFont:[UIFont systemFontOfSize:20]];
    
    return _loginButton;
}
//   设置按钮
-(UIButton *)setButton{
    if (!_setButton) {
        _setButton=[[UIButton alloc]initWithFrame:CGRectMake(20, 30, 30, 30)];
    }
    [_setButton setImage:[UIImage imageNamed:@"设置-2.png"] forState:UIControlStateNormal];
    [_setButton addTarget:self action:@selector(shezhi) forControlEvents:UIControlEventTouchUpInside];
    return _setButton;
}
-(void)shezhi{
}
//   购物车按钮
-(UIButton *)shoppingButton{
    if (!_shoppingButton) {
        _shoppingButton=[[UIButton alloc]initWithFrame:CGRectMake(self.frame.size.width-50, 30, 30, 30)];
    }
    [_shoppingButton setImage:[UIImage imageNamed:@"购物车-2.png"] forState:UIControlStateNormal];
    [_shoppingButton addTarget:self action:@selector(gouwuche) forControlEvents:UIControlEventTouchUpInside];
    return _shoppingButton;
}
-(void)gouwuche{
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:idfer];
    if (!cell) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:idfer];
    }
    if (indexPath.section==0) {
        if (indexPath.row==0) {
            
        cell.accessoryView = [self   initView];
            
        }
    }
    
    
    
    return cell;
}


- (UIView *)initView:(UITableViewCell *)cell {
    // 待付款  待发货  待收货 待评价
    
    UIView *views = [[UIView alloc] initWithFrame:cell.contentView.frame];

    
    CGFloat width = cell.contentView.size.width;
    
    CGFloat leftMargin = (width - 80 * 4 )/5;
    
    cell.accessoryView = views;
    UIButton *paymentButton=[[UIButton alloc]init];
    [paymentButton setBackgroundColor:[UIColor redColor]];
    [views addSubview:paymentButton];
    
    UIButton *deliveryButton=[[UIButton alloc]init];
    UIButton *receivedButton=[[UIButton alloc]init];
    UIButton *evaluationButton=[[UIButton alloc]init];
    paymentButton.sd_layout
    .topSpaceToView(cell.contentView,10)
    .leftSpaceToView(cell.contentView,leftMargin)
    .widthIs(80)
    .heightIs(44);
    
    
    return self;
}


@end
